// pages/collect/collect.js
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        collectList:[],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function () {
        const userId = wx.getStorageSync('login_key').user_id
        wx.request({
          url: `https://www.walkman.asia:2023/list/collect/${userId}`,
          success:(res)=>{
              console.log(res)
              this.setData({
                  collectList:res.data
              })
            //   this.data.collectList.push(res.data)
            console.log(this.data.collectList)
          }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        wx.removeStorageSync('collectPlay')
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },

    playing:function(e){
        console.log(e)
        var playinglist = '' 
        for(var i=0;i<this.data.collectList.length;i++){
            if(e.currentTarget.id==this.data.collectList[i].music_id){
                playinglist = this.data.collectList[i]
            }
        }
        app.globalData.isCollect=true
        console.log(app.globalData.isCollect)
        console.log(playinglist)
        // const playingUrl =(playinglist.singer+'-'+playinglist.music_name).replace(/\s*/g,"")
        // console.log(playingUrl)
        // this.audioCtx = wx.createInnerAudioContext()
        // this.audioCtx.src = `https://www.walkman.asia:2023/getMusic/all/${playingUrl}.mp3`
        // this.audioCtx.play()
        wx.setStorageSync('collectPlay', playinglist)
        // this.data.playingList.push(playinglist)
        // this.setData({
        //     'playing.title': playinglist.music_name,
        //     'playing.singer': playinglist.singer,
        //     'playing.coverImgUrl': `https://www.walkman.asia:2023/getPhoto/music_pic/${playinglist.music_pic}`,
        //     'playing.music_id':playinglist.music_id
        // })
    }
})